Japanese Patent Application Publication No. 2016449715 discloses a semiconductor device in which a switching element and a protection diode are provided in a common semiconductor substrate. A cathode electrode of the protection diode is connected to one terminal of the switching element. An anode electrode of the protection diode is connected to an external circuit. A potential of the anode electrode of the protection diode varies depending on a potential of the one terminal of the switching element. The technique described in Japanese Patent Application Publication No. 2016-149715, determines whether or not a freewheel diode connected in parallel to the switching element is turned on according to the potential of the anode electrode in the protection diode. When the freewheel diode is turned off, the external circuit allows the switching element to be turned on.